<?php
include("connect.php");
?>

<?php
$css = '<link rel="stylesheet" type="text/css" media="all" href="asset/css/class_notification.css">';
$title = 'My Notification';
$page_name = 'notification';
$userid = $_SESSION['userid'];
?>

<?php
$sql = "select user_category from m_user where user_id=".$_SESSION['userid'];
$retval = mysql_query( $sql, $con );
while($row = mysql_fetch_array($retval))
	{
		$user_category = $row[0];
	}
if(isset($_SESSION["userid"]))
	{
		if($user_category ==9)
		{
			include("header_loggedinadmin.php");
		}else
		{
			include("header_loggedin.php");
		}
	}
else
{
	echo '<script>';
		echo "alert('Please Login!');";
		echo 'window.location = "index.php"';
		echo '</script>';
}

?>
<div id="blue_bg">
	<div id="main">
        <div class="wrapper">
        	<div id="content">
            	<div id="white_box">
                	<h3 class="flag_long">NOTIFICATION</h3>
                    <ul class="notif">
                    <?php 
					
				
							$sql2 = "select b.fname,b.lname,d.book_title,c.user_id,a.from_user_id,a.user_book_id,a.notification_date from T_NOTIFICATION  a";
							$sql2 .= " inner join m_user b on a.from_user_id=b.user_id";
							$sql2 .= " inner join t_user_book c on a.user_book_id = c.user_book_id";
							$sql2 .= " inner join m_book d on d.book_id = c.book_id";
							$sql2 .=" WHERE a.to_user_id=".$userid;
							$sql2 .=" ORDER BY  a.notification_date DESC LIMIT 0 ,10";
							
							//echo $sql2;
							
							$retval=mysql_query($sql2,$con);
							
							$todays_date = date("d M Y");
							

							
							if(!$retval){
								die('Could not get data: ' . mysql_error());
							}
							else{
								while($row=mysql_fetch_array($retval)){

									//cek notif date
									$date = date("d M Y", strtotime($row["notification_date"]));
									if($date <= $todays_date){
									echo "<h2><br>$date</h2>";
									$todays_date=$date-1;
									}
								
									if($row[user_id]==$userid){
										echo '<li><a href="my_profile.php?userprofileid='.$row[from_user_id].'">'.$row[fname].' '.$row[lname].'</a> commented on your book, <a href="book_detail.php?userbookid='.$row[user_book_id].'&type=sale">'.$row[book_title].'</a></li>';
									}
									else{
										
										echo '<li><a href="my_profile.php?userprofileid='.$row[from_user_id].'">'.$row[fname].' '.$row[lname].'</a> also commented on <a href="book_detail.php?userbookid='.$row[user_book_id].'&type=buy">'.$row[book_title].'</a></li>';
										
									}
								}
							}
					
						?>
                    </ul>
           		</div>
            </div>
        </div>
    </div>
</div>

<?php
include("footer.php");
?>


